import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'
import { setTitle } from '@/lib/util'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  to.meta&&to.meta.title&&setTitle(to.meta.title)
  if(from.path === '/' && to.path === '/index') {
    window.sessionStorage.setItem('initValue', 'page')
  }
  next()
})
export default router
